﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace QSMonitor
{
    public partial class ucGridView : UserControl
    {
        [Category("QSControl")]
        [Description("設定顯示文字")]
        public string Caption
        {
            set
            {
                groupBox1.Text = value;
            }
            get
            {
                return groupBox1.Text;
            }
        }

        public int RowCount
        {
            get
            { return dataGridView1.RowCount; }
        }

        public int ColumnCount
        {
            get
            {
                return dataGridView1.ColumnCount;
            }
        }

        /// <summary>
        /// 當GridView 中的CellClick & CellEnter 觸發時，把事件傳出來
        /// </summary>
        public event DataGridViewCellEventHandler RowEnter = null;

        protected int rowNO = -1;

        public int RowNO
        {
            set
            {
                rowNO = value;
            }
            get
            {
                return rowNO;
            }
        }

        public ucGridView()
        {
            InitializeComponent();
        }

        public void SetData(DataTable p_dt)
        {
            dataGridView1.DataSource = p_dt;
        }

        public void NoData()
        {
            dataGridView1.DataSource = null;
        }

        public DataGridViewCell GetDataGridViewCell(int p_columnIndex, int p_rowIndex)
        {
            return dataGridView1[p_columnIndex, p_rowIndex];
        }

        //private void bindDataGridViewCellEventHandler(object sender, DataGridViewCellEventArgs e)
        //{
        //    if (rowNO != e.RowIndex)
        //    {
        //        rowNO = e.RowIndex;
        //        if (GVCellEvent != null)
        //        {
        //            GVCellEvent(sender, e);
        //        }
        //    }
        //}

        private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            if ((RowEnter != null) )
            {
                RowEnter(sender, e);
            }
        }


    }
}
